package com.interest.plus2.provider;

import com.interest.plus2.view.mainview.CurriculumView;
import com.interest.plus2.view.mainview.HomeView;
import com.interest.plus2.view.mainview.MyView;
import com.interest.plus2.view.mainview.StudentShowView;
import ohos.agp.components.*;
import ohos.app.Context;

import java.util.List;

public class MainPagerProvider extends PageSliderProvider {
    private Context mContext;
    // 数据源，每个页面对应list中的一项
    private List<DataItem> list;

    public MainPagerProvider(List<DataItem> list,Context context) {
        this.list = list;
        mContext = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object createPageInContainer(ComponentContainer componentContainer, int i) {
        Component component;
        switch (i) {
            case 0:
                component = new HomeView(mContext);
                break;
            case 1:
                component = new CurriculumView(mContext);
                break;
            case 2:
                component = new StudentShowView(mContext);
                break;
            case 3:
                component = new MyView(mContext);
                break;
            default:
                Text text = new Text(mContext);
                text.setText("没有生成页面？");
                component = text;
        }
        componentContainer.addComponent(component);
        return component;
    }

    @Override
    public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o) {
        componentContainer.removeComponent((Component) o);
    }

    @Override
    public boolean isPageMatchToObject(Component component, Object o) {
        return true;
    }

    //数据实体类
    public static class DataItem {
        String mText;

        public DataItem(String txt) {
            mText = txt;
        }
    }
}
